<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>
<body>
    <h1>axios的基本使用</h1>
    <button class="tsetget">发送get请求</button>
    <button class="tsetpost">发送post请求</button>
    <button class="tsetput">发送put请求</button>
    <button class="tsetdelete">发送delete请求</button>
    <script>
        //获取按钮
        const btn = document.querySelectorAll('button');

        //get请求
        btn[0].onclick = function(){
            //发送get方法
            axios.get("http://localhost:3000/posts/1").then(v=>{
                console.log(v);
            });
        }
        //post请求
        btn[1].onclick=function(){
            //发送Ajax请求
            axios.post(
                "http://localhost:3000/comments",
                {
                    "body": "good",
                    "postId": 2
                }
            ).then(v=>{
                console.log(v);
            });
        }
    </script>
</body>
</html>